package dao;

import entity.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import utils.DruidUtils;

import java.sql.SQLException;

public class UserDaoImp implements UserDao{

    //登陆
    @Override
    public User userLogin(User user) {
        try {
            QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());
            String sql = "select * from user where userName = ? and password = ?";
            Object[] param = {user.getUsername(),user.getPassword()};
            User user1 = queryRunner.query(sql, new BeanHandler<User>(User.class),param);
            if(user1 != null){
                return user1;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
